#include <stdio.h>

int main() {
    int A;
    scanf("%d", &A);
    
    int count = 0;
    for (int i = A; i < A + 4; i++) {
        for (int j = A; j < A + 4; j++) {
            for (int k = A; k < A + 4; k++) {
                if (i != j && i != k && j != k) {
                    printf("%d", i * 100 + j * 10 + k);
                    count++;
                    if (count % 6 == 0)
                        printf("\n");
                    else
                        printf(" ");
                }
            }
        }
    }
    if (count % 6 != 0)
        printf("\n");

    return 0;
}
